#pragma once
// -------------------------------------------------
// BlinKit - BlinKit Library
// -------------------------------------------------
//   File Name: qjs_event_listener_impl.h
// Description: EventListenerImpl Class
//      Author: Ziming Li
//     Created: 2022-03-31
// -------------------------------------------------
// Copyright (C) 2022 MingYang Software Technology.
// -------------------------------------------------

#ifndef BLINKIT_QJS_EVENT_LISTENER_IMPL_H
#define BLINKIT_QJS_EVENT_LISTENER_IMPL_H

#include "blinkit/blink/renderer/core/events/event_listener.h"
#include "third_party/quickjs/quickjs.h"

namespace BlinKit {
namespace qjs {

class EventListenerImpl final : public EventListener
{
public:
    static GCRefPtr<EventListener> Wrap(JSContext *ctx, JSValue listener, bool createIfNotExists);
    ~EventListenerImpl(void) override;
private:
    EventListenerImpl(JSContext *ctx, JSValue listener);

    // blink::EventListener
    bool operator==(const EventListener &other) const override { return this == &other; }
    void handleEvent(ExecutionContext *executionContext, Event *event) override;

    JSContext *m_ctx;
    JSValue m_listener;
};

} // namespace qjs
} // namespace BlinKit

#endif // BLINKIT_QJS_EVENT_LISTENER_IMPL_H
